package demo02;

import java.sql.*;

public class Test01 {
    public static void main(String[] args) {
        try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test2", "root", "mysql");
             PreparedStatement preparedStatement = connection.prepareStatement("insert into user values(null,?,?,?)")) {
            Class.forName("com.mysql.cj.jdbc.Driver");
            System.out.println("加载成功！");
            preparedStatement.setString(1, "张三");
            preparedStatement.setString(2, "123456");
            preparedStatement.setString(3, "China");
            int i = preparedStatement.executeUpdate();
            if (i > 0) {
                System.out.println("添加成功！");
            }
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }
}
